import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig(({ mode }) => {
  // eslint-disable-next-line no-undef
  const env = loadEnv(mode, process.cwd(), '')

  return {
    base: env.VITE_APP_BASE_PRE,
    plugins: [vue()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    build: {
      outDir: env.VITE_APP_OUT_DIR,
      chunkSizeWarningLimit: 1500
    },
    css: {
      preprocessorOptions: {
        scss: {
          /**全局变量引入 */
          additionalData: ` @use "@/assets/styles/variables.scss" as *; `,
          javascriptEnabled: true
        }
      }
    },
    server: {
      /**9100就是你的终身代号 */
      port: 9100,
      /* proxy: {
        [env.VITE_APP_PREFIX_API]: {
          target: env.VITE_APP_PROXY_ORIGIN,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      } */
    }
  }
})
